<template>
    <div class="container">
        <div class="flex-box-align" style="padding-bottom: 20px;border-bottom: 1px solid #f4f4f4">
            <div class="flex">问诊单</div>
        </div>

        <ul class="inquiry-info flex">
            <li>
                <span>姓名：</span>
                <span>{{name}}</span>
            </li>
            <li class="flex-box-align">
                <span>地区：</span>
                <v-distpicker :province="province" :city="city" :area="district"
                              @province="selectProvince"
                              @city="selectCity"
                              @area="selectArea"
                >

                </v-distpicker>
            </li>
            <li class="flex-box-align">
                <span>医院首诊时间：</span>
                <el-date-picker
                        v-model="firstInquiryTime"
                        type="datetime"
                        placeholder="例：2018-02-01 13:00">
                </el-date-picker>            </li>
            <li class="flex-box-align">
                <span>自述：</span>
                <el-input type="textarea" autosize :maxlength="500" style="width: 200px" v-model="description" placeholder="请输入"></el-input>
            </li>
            <li class="flex-box-align">
                <span>看诊时间：</span>
                <el-date-picker
                        v-model="secondInquiryTime"
                        type="datetime"
                        placeholder="例：2018-02-01 13:00">
                </el-date-picker>
            </li>
            <li class="flex-box-align">
                <span>检查结果：</span>
                <el-upload
                        class="avatar-uploader"
                        :action="upLoadUrl"
                        :show-file-list="false"
                        :on-success="handleCheckSuccess"
                        :before-upload="beforeAvatarUpload">
                    <img v-if="check.img" :src="check.img" class="avatar">
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
            </li>
            <li class="flex-box-align">
                <span>病例：</span>
                <el-upload
                        class="avatar-uploader"
                        :action="upLoadUrl"
                        :show-file-list="false"
                        :on-success="handleCaseSuccess"
                        :before-upload="beforeAvatarUpload">
                    <img v-if="casePhoto.img" :src="casePhoto.img" class="avatar">
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
            </li>
        </ul>
        <div  style="margin-top: 40px;text-align: center;width:400px">
            <el-button type="primary" @click="handleClickSave">保存</el-button>
            <el-button type="primary" @click="$router.back(-1)">返回</el-button>
        </div>

    </div>
</template>

<script>
    let CONSTANT = require('../../constant/constant.js');
    let common = require("../../common.js");
    import {parseUrlParams} from "../../util";
    import VDistpicker from 'v-distpicker'

    export default {
        data() {
            return {
                showDetail: true,
                list: [],
                firstInquiryTime: "",
                secondInquiryTime: "",
                province: "",
                city: "",
                district: "",
                description: "",
                casePhoto: {
                    casePhotoId: "",
                    img: ""
                },
                check: {
                    checkResultPhotoId: "",
                    img :""
                },
                name: "",
                upLoadUrl: ""
            }
        },
        components: {
            VDistpicker
        },
        mounted() {
            let sessionId = common.getCookie('sessionId');
            this.upLoadUrl = CONSTANT.URL.COMMON.UPLOAD + '?sessionId='+sessionId;
            this.name = decodeURI(parseUrlParams("name"))
        },
        methods: {
            selectProvince(val) {
                this.province = val.value
            },
            selectCity(val) {
                this.city = val.value
            },
            selectArea(val) {
                this.district = val.value
            },
            handleCheckSuccess(res, file) {
                this.check.checkResultPhotoId = res.data.bussData.fileId;
                this.check.img = res.data.bussData.fileUrl;
            },
            handleCaseSuccess(res, file) {
                this.casePhoto.casePhotoId = res.data.bussData.fileId;
                this.casePhoto.img = res.data.bussData.fileUrl;
            },
            beforeAvatarUpload(file) {

            },
            handleClickSave() {
                if (!this.province) {
                    this.$message.error('请选择省份');
                    return false
                }
                if (!this.city) {
                    this.$message.error('请选择城市');
                    return false
                }
                if (!this.district) {
                    this.$message.error('请选择地区');
                    return false
                }
                if (!this.firstInquiryTime) {
                    this.$message.error('请输入医院首诊时间');
                    return false
                }
                if (!this.description) {
                    this.$message.error('请输入自述');
                    return false
                }
                if (!this.secondInquiryTime) {
                    this.$message.error('请输入看诊时间');
                    return false
                }
                if (!this.check.checkResultPhotoId) {
                    this.$message.error('请上传检查结果');
                    return false
                }
                if (!this.casePhoto.casePhotoId) {
                    this.$message.error('请上传病例');
                    return false
                }
                let params = {
                    patientId: parseUrlParams("id"),
                    firstInquiryTime: this.firstInquiryTime,
                    secondInquiryTime: this.secondInquiryTime,
                    province: this.province,
                    city: this.city,
                    district: this.district,
                    description: this.description,
                    casePhotoId: this.casePhoto.casePhotoId,
                    checkResultPhotoId: this.check.checkResultPhotoId,
                }
                common.requestAjax(CONSTANT.URL.PATIENT.INQUIRYEDIT, JSON.stringify(params), {}, (res) => {
                    if (res.status == 200) {
                        this.$message({
                            message: res.msg,
                            type: 'success'
                        });
                        this.$router.back(-1)
                    }
                }, null)
            }
        }
    }
</script>

<style lang="scss">
    .container {
        .inquiry-info {
            li {
                margin-top: 20px;
            }
            li>span:nth-child(1) {
                display: inline-block;
                width: 200px;
            }

            .avatar-uploader .el-upload {
                border: 1px dashed #d9d9d9;
                border-radius: 6px;
                cursor: pointer;
                position: relative;
                overflow: hidden;
            }
            .avatar-uploader .el-upload:hover {
                border-color: #409EFF;
            }
            .avatar-uploader-icon {
                font-size: 28px;
                color: #8c939d;
                width: 150px;
                height: 150px;
                line-height: 150px;
                text-align: center;
            }
            .avatar {
                width: 150px;
                height: 150px;
                display: block;
            }
        }




    }
</style>
